package com.lei2j.singleton;

public class Singleton {

	private volatile static Singleton SINGLETON;
	
	private Singleton() {}
	
	public static Singleton getInstance() {
		if(SINGLETON==null) {
			System.out.println("1");
			synchronized(Singleton.class) {
				System.out.println("2");
				if(SINGLETON==null) {
					System.out.println("3");
					SINGLETON = new Singleton();
				}
			}
		}
		return SINGLETON;
	}
	
	private static class SingletonInstance {
		private static final Singleton SINGLETON = new Singleton();
	} 
	
	public static Singleton getInstance1() {
		return SingletonInstance.SINGLETON;
	}
	
	public static void main(String[] args) {
		System.out.println(getInstance());
	}
}
